package com.szrt.java.day20170109.demo07;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

public class MapTest {

	@Test
	public void mapTest(){
		
		Map<String,Student> map = new HashMap<String,Student>();
		
		Student stu1 = new Student();
		stu1.setName("胡斌");
		stu1.setAge(24);
		stu1.setPhoneNum("18676758812");
		
		Student stu2 = new Student();
		stu2.setName("陈皋");
		stu2.setAge(23);
		stu2.setPhoneNum("18617067326");
		
		Student stu3 = new Student();
		stu3.setName("刘浩");
		stu3.setAge(24);
		stu3.setPhoneNum("15766472116");
		
		map.put("胡斌", stu1);
		map.put("陈皋", stu2);
		map.put("刘浩", stu3);
		
		Set<String> set = map.keySet();
		
		Iterator<String> it = set.iterator();
		
		//map.get(key) 相当于对应key的Student对象
		while(it.hasNext()){
			String key = it.next();
			System.out.println(key+" "+map.get(key));
		}
		
	}
}
